package com.achobeta.recruitment.controller.manager;

import com.achobeta.recruitment.common.AppResult;
import com.achobeta.recruitment.common.ResultCode;
import com.achobeta.recruitment.common.Rule;
import com.achobeta.recruitment.model.ManageRemarks;
import com.achobeta.recruitment.model.Manager;
import com.achobeta.recruitment.service.manager.ManageRemarksService;
import com.achobeta.recruitment.utils.LimitUtils;
import com.achobeta.recruitment.utils.SessionUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.NonNull;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.Date;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 马拉圈
 * Date: 2023-11-09
 * Time: 12:48
 */
@Slf4j
@RestController
@RequestMapping("/remarks")
@Api(tags = "管理员标注信息相关")
public class ManageRemarksController {


    @Autowired
    private ManageRemarksService manageRemarksService;


    @ApiOperation(value = "保存管理员标记信息", notes = "无data")
    @PostMapping("/save")
    public AppResult saveRemarksByOpenid(HttpServletRequest request,
                                        @NonNull @ApiParam("openid") @RequestParam("openid") String openid,
                                        @ApiParam("安排内容") @RequestParam(required = false, value = "arrangement") String arrangement,
                                        @ApiParam("结论内容") @RequestParam(required = false, value = "conclusion") String conclusion,
                                        @ApiParam("管理侧备注") @RequestParam(required = false, value = "remark") String remark){
        // 获取当前登录用户
        Manager manager = SessionUtils.getManager(request);
        // 判断是否有权限
        if(!LimitUtils.hasPower(manager, Rule.UPDATE_REMARKS_RULE)) {
            log.warn(ResultCode.FAILED_MANAGER_NOT_POWERS.toString());
            return AppResult.failed(ResultCode.FAILED_MANAGER_NOT_POWERS);
        }
        // 构造修改用的对象
        ManageRemarks updateRemarks = new ManageRemarks();
        updateRemarks.setRemark(remark);
        updateRemarks.setConclusion(conclusion);
        updateRemarks.setArrangement(arrangement);
        updateRemarks.setUpdateTime(new Date());
        updateRemarks.setDeleteState((byte) 0);
        // 调用service层
        manageRemarksService.saveManageRemarks(openid, updateRemarks);
        // 成功
        return AppResult.success();
    }



}
